﻿#region Header
// ------------------------ Licence / Copyright ------------------------
// 
// ScrumTable for Scrum Meeting Support
// Copyright © HSR - Hochschule für Technik Rapperswil
// All Rights Reserved
// 
// Author:
//  Michael Gfeller Silvan Gehrig Patrick Boos
// 
// ---------------------------------------------------------------------
#endregion

#region Usings

using ScrumTable.Common.Collections;

#endregion

namespace ScrumTable.DL.Data.Excel
{
    /// <summary>
    /// This class holds multiple indexes for the same value. Every indexed
    /// value entry is bound and optimized by the associated key type. In order
    /// to retrieve the keys of a value, you have to provide a method pointer
    /// as first constructor argument.
    /// </summary>
    internal class WorkItemMultiIndex : MultiIndex<WorkItemMultiIndexEntry>
    {
        #region Declarations
        //--------------------------------------------------------------------
        // Declarations
        //--------------------------------------------------------------------

        internal const string BackEndId = "BackEndId";
        internal const string IdField = "Id";

        #endregion

        #region Properties
        //--------------------------------------------------------------------
        // Properties
        //--------------------------------------------------------------------

        #endregion

        #region Constructors / Destructor
        //--------------------------------------------------------------------
        // Constructors / Destructor
        //--------------------------------------------------------------------

        /// <summary>
        /// Creates a new WorkItemMultiIndex instance with the specified data.
        /// </summary>
        internal WorkItemMultiIndex()
        {
        }

        #endregion

        #region Methods
        //--------------------------------------------------------------------
        // Methods
        //--------------------------------------------------------------------

        /// <summary>
        /// Gets the value according to the specified id.
        /// </summary>
        /// <param name="id">Specifies the id to check.</param>
        /// <returns>Returns the retrieved element.</returns>
        internal WorkItemMultiIndexEntry GetById(int id)
        {
            return Get(IdField, id);
        }

        /// <summary>
        /// Gets the value according to the specified id.
        /// </summary>
        /// <param name="backEndId">Specifies the backEndId to check.</param>
        /// <returns>Returns the retrieved element.</returns>
        internal WorkItemMultiIndexEntry GetByBackEndId(string backEndId)
        {
            return Get(BackEndId, backEndId);
        }

        /// <summary>
        /// Tries to retrieve the value with the from the index.
        /// </summary>
        /// <param name="id">Specifies the id to check.</param>
        /// <param name="retrievedValue">Specifies the reference of the value to retrieve.</param>
        /// <returns>Returns true if the value with the given key could be found, otherwise false.</returns>
        internal bool TryGetById(int id, out WorkItemMultiIndexEntry retrievedValue)
        {
            return TryGet(IdField, id, out retrievedValue);
        }

        /// <summary>
        /// Tries to retrieve the value with the from the index.
        /// </summary>
        /// <param name="backEndId">Specifies the id to check.</param>
        /// <param name="retrievedValue">Specifies the reference of the value to retrieve.</param>
        /// <returns>Returns true if the value with the given key could be found, otherwise false.</returns>
        internal bool TryGetByBackEndId(int backEndId, out WorkItemMultiIndexEntry retrievedValue)
        {
            return TryGet(BackEndId, backEndId, out retrievedValue);
        }

        /// <summary>
        /// Returns true if the current index contains a value with the given key.
        /// </summary>
        /// <param name="id">Specifies the id to check.</param>
        internal bool ContainsId(int id)
        {
            return ContainsKey(IdField, id);
        }

        /// <summary>
        /// Tries to retrieve the value with the from the index.
        /// </summary>
        /// <param name="backEndId">Specifies the id to check.</param>
        /// <returns>Returns true if the value with the given key could be found, otherwise false.</returns>
        internal bool ContainsBackEndId(string backEndId)
        {
            return ContainsKey(BackEndId, backEndId);
        }

        #endregion

        #region Events
        //--------------------------------------------------------------------
        // Events
        //--------------------------------------------------------------------

        #endregion
    }
}